/*
 * CS_VIP_INFO.cpp
 *
 *  Created on: 2014. 3. 6.
 *      Author: the2
 */


#include "../../User.h"
#include "../../Command.h"
#include "../../NResource/Static.h"
#include "../../NLogic/Buff.h"

namespace ProjectZ { namespace NCommand {

/*
// VIP 정보
CS_VIP_INFO	0x3100
{
}

SC_VIP_INFO	0x3101
{
	s16	s16ack;
	u32	u32point;			// VIP 포인트
	u32	u32buffTime_min;	// VIP 버프 남은 시간(분단위)
	u32	u32vip1_point;		// VIP 1 등급 기준 포인트 (2000)
	u32	u32vip2_point;		// VIP 2 등급 기준 포인트 (5000)
	u32	u32vip3_point;		// VIP 3 등급 기준 포인트 (15000)
	u32	u32max_point;		// VIP 최대 포인트 (25000)
}
*/

void Command::CS_VIP_INFO(User * pUser, ::Network::Packet * pPacket)
{
	PREPARE_PACKET;

	if (false == NResource::Static::Instance().GetContentsOpenResource()->IsOpen(VIP_SYSTEM))
	{
		DEBUGLOG("false == NResource::Static::Instance().GetContentsOpenResource()->IsOpen(VIP_SYSTEM)");
		::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
		*pAck	<< static_cast<int16_t>(ACK_NOT_OPEN)
				;
		pAck->MakePacket(CMD_SC_VIP_INFO);
		pUser->Send(pAck);
		return;
	}

	pUser->GetBuff()->RefleshVIPBuff();

	int vpBuffTime = 0;

	NResource::VIPResource::Data & vipData = NResource::Static::Instance().GetVIPResource()->GetData();

	if (pUser->GetUserInfo().reserve4 > vipData._VIP1_VP)
	{
		int vipPoint = pUser->GetUserInfo().reserve4 - vipData._VIP1_VP;
		if (vipPoint < vipData._MINUS_VP_AMOUNT_PER_PERIOD)
			vpBuffTime = vipData._MINUS_VP_MIN_PERIOD  * 60;
		else
		{
			if (0 < vipPoint % vipData._MINUS_VP_AMOUNT_PER_PERIOD)
				vpBuffTime = (vipPoint / vipData._MINUS_VP_AMOUNT_PER_PERIOD) * (vipData._MINUS_VP_MIN_PERIOD  * 60) + vipData._MINUS_VP_MIN_PERIOD  * 60;
			else
				vpBuffTime = (vipPoint / vipData._MINUS_VP_AMOUNT_PER_PERIOD) * (vipData._MINUS_VP_MIN_PERIOD  * 60);
		}

		vpBuffTime /= 60;
	}

	TESTLOG("%s : vip_point=%d, BuffTime=%d, vip1=%d, vip2=%d, vip3=%d, vip_max=%d", __FUNCTION__,
			pUser->GetUserInfo().reserve4, vpBuffTime, vipData._VIP1_VP, vipData._VIP2_VP, vipData._VIP3_VP, vipData._MAX_VP);

	::Network::Packet * pAck = ::Network::GETPACKETPOOL()->SEND_NEW();
	*pAck	<< static_cast<int16_t>(ACK_OK)
			<< static_cast<uint32_t>(pUser->GetUserInfo().reserve4) // vip point
			<< static_cast<uint32_t>(vpBuffTime) // vip buff
			<< static_cast<uint32_t>(vipData._VIP1_VP) // vip 1
			<< static_cast<uint32_t>(vipData._VIP2_VP) // vip 2
			<< static_cast<uint32_t>(vipData._VIP3_VP) // vip 3
			<< static_cast<uint32_t>(vipData._MAX_VP) // vip max point
			;
	pAck->MakePacket(CMD_SC_VIP_INFO);
	pUser->Send(pAck);
}

} /*NCommand*/ } /*ProjectZ*/

